package Chess.Moves;

import Chess.*;
import Chess.Pieces.*;
import Chess.Pieces.Piece.*;

/**
 *	A class representing a NormalMove in Chess.
 *
 *	@author		Jeff Chan
 */
public class NormalMove extends Move {

	private NormalMove(Piece piece, Square startSquare, Square endSquare) {
		super(piece, startSquare, endSquare);
	}

	public static boolean canBeExecuted(Board board, Square startSquare, Square endSquare) {
		boolean canBeExecuted = false;
		
		if (board != null) {
			Piece piece = board.getPiece(startSquare);
			if (piece != null && piece.canMove(board, startSquare, endSquare)) {
				canBeExecuted = true;
			}
		}
		
		return canBeExecuted;
	}

	public static NormalMove execute(Board board, Square startSquare, Square endSquare) {
		Piece piece = board.getPiece(startSquare);
		board.movePiece(piece, startSquare, endSquare);
		piece.incrementMoveCount();
		return new NormalMove(piece, startSquare, endSquare);
	}
	
	public void undo(Board board) {
		board.movePiece(piece, endSquare, startSquare);
		piece.decrementMoveCount();
	}

	public MoveType getMoveType() {
		return MoveType.NORMAL;
	}
}
